package xginxlog

import (
	"encoding/json"

	"gitee.com/xiaoyutab/xgotool/optional/xlog"
	"gitee.com/xiaoyutab/xgotool/xgin"
	"gitee.com/xiaoyutab/xgotool/xstring"
	"github.com/gin-gonic/gin"
)

// 查看用户日志记录
//
//	GET	/user.log
func userLog(c *gin.Context) *xgin.Response {
	type users struct {
		Uid json.Number `json:"uid" form:"uid"` // 他人用户ID
	}
	u := users{}
	if err := xgin.Bind(c, &u); err != nil {
		return xgin.Resp().Error(err)
	}
	uid := c.GetUint("uid")
	if xstring.JUint(u.Uid) > 0 {
		uid = xstring.JUint(u.Uid)
	}
	count, lis, err := xlog.GetLogUser(uid, c.GetInt("offset"), c.GetInt("limit"))
	if err != nil {
		return xgin.Resp().Error(err)
	}
	return xgin.Resp().Page(c, lis, count)
}
